package cn.mln521.annotation.demo1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Spring的Bean管理的注解方式
 *      传统方式需要去XML中配置<bean id="" class=""></bean>
 */
//@Component
@Service("userService")
public class UserService {

    @Value("米饭")
    private String something;

    /**@Autowired
     *      默认按照类型进行注入
     *      – 如果存在两个相同Bean类型相同，则按照名称注入
     *
     */
      //@Autowired
     /* @Autowired
      @Qualifier("userDao111")*/
     @Resource(name = "userDao111")
    private UserDao userDao;

    public String sayHello(String name) {
        return "你好" + name;
    }

    public void eat() {
        System.out.println("eat:" + something);
    }

    public void save() {
        System.out.println("userService中的eat的方法");
        userDao.save();
    }
}
